package com.xsd.awen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xsd.awen.domain.entity.Task;
import com.xsd.awen.domain.po.TaskPagePo;
import com.xsd.awen.domain.vo.TaskVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TaskMapper extends BaseMapper<Task> {

    @Select("<script> " +
            " select u.*,p.cname projectName,a.name appName from t_tk_task u,t_tk_project p,t_tk_app a " +
            " where u.project_id = p.id and u.app_id = a.id " +
            "<if test=\"task.name != null and task.name != ''\"> and u.name like CONCAT('%', #{task.name}, '%')</if>" +
            "<if test=\"task.appId != null and task.appId != ''\"> and u.app_id = #{task.appId}</if>" +
            "<if test=\"task.status != null \"> and u.status = #{task.status}</if>" +
            "<if test=\"task.projectId != null and task.projectId != ''\"> and u.project_id = #{task.projectId}</if>" +
            "<if test=\"task.gs != null\"> and u.gs = #{task.gs}</if>" +
            " order by u.create_time desc " +
            "</script>")
    List<TaskPagePo> page(TaskVo taskVo);

    @Select(" select count(1) from t_tk_task where name = #{name} ")
    Integer countTask(Task task);

    @Select(" select count(1) from t_tk_task where name = #{name} and id != #{id} ")
    Integer countUpdateTask(Task task);

    @Select(" select count(1) from t_tk_task where app_id = #{appId} ")
    Integer countTaskByAppId(Task task);


    @Select(" select count(1) from t_tk_user_task where task_id = #{id} ")
    Integer countUserTaskByTaskId(Task task);
}